#include "aesutil.h"
#include "qaesencryption.h"
#include <QCryptographicHash>

QByteArray AESUtil::encrypt(const QString &content, const QByteArray &key)
{
    QAESEncryption encryption(QAESEncryption::AES_128, QAESEncryption::CBC, QAESEncryption::PKCS7);
    QByteArray encodeText = encryption.encode(content.toUtf8(), key, key);
    return encodeText.toHex();
}

QString AESUtil::decrypt(const QString &content, const QByteArray &key)
{
    QAESEncryption encryption(QAESEncryption::AES_128, QAESEncryption::CBC, QAESEncryption::PKCS7);
    QByteArray decodeText = encryption.decode(QByteArray::fromHex(content.toLocal8Bit()), key, key);
    return QString::fromUtf8(encryption.removePadding(decodeText));
}

